/**
 * Copyright (c)  2018-2028 DHCC, Inc.
 * All rights reserved.
 * <p>
 * This software is the confidential and proprietary information of DHCC,
 * Inc. ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into with DHCC.
 */
package cn.com.lookang.packager;

import cn.com.lookang.bo.CpqReportBo;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.Version;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 *
 * @author: liulekang
 * @Date: 2019/7/16 
 */
public class PackagerMain {

    private static final Template template = getTemplate();

    public static void main(String[] args) {
        System.out.println("packager start......");
        try {
            CpqReportBo cpqReportBo = CpqReportBo.build();
            long startTime = System.currentTimeMillis();
            FileWriter fileWriter = new FileWriter(new File("C:\\Users\\Administrator\\Desktop\\freemarker\\report.txt"));
            template.process(cpqReportBo,fileWriter);
            System.out.println("耗时："+(System.currentTimeMillis() - startTime) + "ms");
            System.out.println("packager end.....");
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    private static Template getTemplate() {
        Version version = Configuration.getVersion();
        Configuration configuration = new Configuration(version);
        try {
            configuration.setDirectoryForTemplateLoading(new File("E:\\gitee_code\\freemarker-demo\\src\\main\\resources\\template"));

            configuration.setSharedVariable("dicConvert",new DicConvert());
            configuration.setClassicCompatible(true);

            Template template = configuration.getTemplate("report.ftl");
            return template;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
